import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Vector2f;

import it.randomtower.engine.entity.Entity;


public class TwoRobot extends Entity {
	int playerX;
	int playerY;
	Animation player;
	boolean selected;
	Color highlighted = new Color(1.0f,1.0f,.5f);
	
	public void setSelected(boolean x){
		selected = x;
	}

	public TwoRobot(int x, int y) throws SlickException {
		super(x, y);
		playerX = x;
		playerY = y;
		System.out.println("X:Y, "+ playerX + ":"+ playerY);
		SpriteSheet sheet = new SpriteSheet("images/karbonator.png", 32, 32);
		player = new Animation();
		player.setAutoUpdate(true);
		for (int frame = 0; frame < 3; frame++) {
			player.addFrame(sheet.getSprite(frame, 0), 150);
		}
		
	}

	public TwoRobot(int x, int y, Image image) {
		super(x, y, image);
	}

	public boolean isPlayerAtLocation(int mouseX, int mouseY) {
		System.out.println(this.playerY + ", " + this.playerX + ":" + mouseY +", " + mouseX);
		return(playerY == mouseY && playerX == mouseX);
	}

	//removed after realizing robot should never control his own movement
	/*public void movePlayer(GameContainer container, ArrayList<TwoRobot> players) {
		Input input = container.getInput();
		int mouseX = input.getMouseX();
		int mouseY = input.getMouseY();
		mouseX = (mouseX / 16) *16;
		mouseY = (mouseY / 16) *16;
		for(TwoRobot player:players){
			if(player.isPlayerAtLocation(mouseX, mouseY))
				break;
			else{
				playerX = mouseX;
				playerY = mouseY;
			}
		}
		
	}*/
	
	public void movePlayer(int x, int y){
		System.out.println("Moving Player");
		playerX = x;
		playerY = y;
		setPosition(new Vector2f(playerX, playerY));
	}
	
	public void update(GameContainer container, int delta) throws SlickException{
		
		super.update(container, delta);
		
	}
	
	public void render(GameContainer container, Graphics g) {
		try {
			super.render(container, g);
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(selected)
			g.drawAnimation(player, playerX, playerY, highlighted);
		else
			g.drawAnimation(player, playerX, playerY);
		
	}

}
